//
// Created by Yun on 2025/2/12.
//

#include "app_demo.h"

void App_Led_Demo(void* pArgs)
{
    (void)pArgs;
    Dev_Led_On(&stDev_Red_Led);
}

void App_Led2_Demo(void* pArgs)
{
    (void)pArgs;

    Dev_Led_Off(&stDev_Red_Led);
}

void App_Led1_Demo(void* pArgs)
{
    (void)pArgs;
    Dev_Led_Toggle(&stDev_Blue_Led);
}

void App_Tim_Demo(void* pArgs)
{
    (void)pArgs;
    Dev_Led_Toggle(&stDev_Red_Led);
}



uint8_t y = 0;

void App_Button_Demo(void* pArgs)
{
    (void)pArgs;

    /* 锁定设备 */
    DEV_LOCK((&stDev_Blue_Led));

    const uint8_t zh16x16[][32] = {
/* 3 波 */ {0x10,0x60,0x02,0x0c,0xc0,0x00,0xf8,0x88,0x88,0x88,0xff,0x88,0x88,0xa8,0x18,0x00,0x04,0x04,0x7c,0x03,0x80,0x60,0x1f,0x80,0x43,0x2c,0x10,0x28,0x46,0x81,0x80,0x00,},
/* 4 特 */ {0x40,0x3c,0x10,0xff,0x10,0x10,0x40,0x48,0x48,0x48,0x7f,0x48,0xc8,0x48,0x40,0x00,0x02,0x06,0x02,0xff,0x01,0x01,0x00,0x02,0x0a,0x12,0x42,0x82,0x7f,0x02,0x02,0x00,},
/* 5 律 */ {0x00,0x10,0x88,0xc4,0x33,0x10,0x54,0x54,0x54,0xff,0x54,0x54,0x7c,0x10,0x10,0x00,0x02,0x01,0x00,0xff,0x00,0x10,0x12,0x12,0x12,0xff,0x12,0x12,0x12,0x10,0x00,0x00,},
/* 6 ： */ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
/* 2 9 */ {0x00,0xe0,0x10,0x08,0x08,0x08,0x10,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0x22,0x22,0x22,0x11,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
/* 1 6 */ {0x00,0xe0,0x10,0x88,0x88,0x88,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x11,0x20,0x20,0x20,0x11,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
/* 0 0 */ {0x00,0xe0,0x10,0x08,0x08,0x08,0x10,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x10,0x20,0x20,0x20,0x10,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
/* 0 0 */ {0x00,0xe0,0x10,0x08,0x08,0x08,0x10,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x10,0x20,0x20,0x20,0x10,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
    };
    uint8_t x = 0;

    Dev_OLed_4P_Clear(&stDev_OLed_4p);

    for(int i=0;i<8;i++)
    {
        uint8_t* u8Font = (uint8_t*)zh16x16[i];

        Dev_OLed_4P_Show(&stDev_OLed_4p,
                         x, y,
                         u8Font,
                         16, 16);
        x+=16;
    }
    y++;
}

void App_Button2_Demo(void* pArgs)
{

    (void)pArgs;

    /* 解锁设备 */
    DEV_UNLOCK((&stDev_Blue_Led));

    Dev_OLed_4P_Clear(&stDev_OLed_4p);

    const uint8_t pic[] = {
        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0x1f, 0x0f, 0x07, 0x31, 0x18, 0x1c, 0x1e, 0xff, 0x3f, 0x0f, 0x80, 0xf6, 0x7e, 0x0f, 0xc3, 0xf1, 0xfc, 0xfe, 0xff, 0x87,
                0xe1, 0xff, 0x07, 0x00, 0xc0, 0xe0, 0xe4, 0xec, 0xec, 0xdc, 0x3c, 0x7c, 0xbc, 0xc8, 0xc0, 0x01, 0x0f, 0x3e, 0x38, 0x01, 0x07, 0x3f, 0xff, 0xff,
                0xfe, 0xf0, 0x01, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x80, 0x80, 0x80, 0xc0, 0x0f, 0x00, 0x00, 0x3f, 0x3f, 0x38, 0x30,
                0x03, 0x01, 0x03, 0x07, 0xe3, 0xf1, 0xe1, 0xc1, 0xb0, 0xb8, 0xff, 0x7f, 0x79, 0x38, 0x38, 0x9f, 0xa7, 0xb0, 0x8f, 0x9f, 0x3f, 0x3f, 0x7f, 0x78,
                0xf8, 0xb8, 0x9c, 0x00, 0x01, 0x0f, 0x0f, 0xc1, 0xf0, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xe7, 0x3e, 0x78, 0xe0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe0, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xe0, 0xc7, 0xd7, 0x97, 0xb7, 0xa7,
                0xa7, 0x87, 0xc7, 0xc7, 0xe0, 0xf1, 0xff, 0xff, 0xf8, 0xe0, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x1f, 0x1f, 0x0f, 0xc7, 0xc7, 0xe3, 0xe3, 0xf1, 0xf1, 0xf1,
                0x01, 0x01, 0x01, 0x01, 0xf1, 0xf1, 0xf1, 0xe0, 0xe0, 0xc0, 0xc0, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
                0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x81, 0x40, 0x60, 0x60, 0x20, 0x00, 0xd8, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x07, 0x01, 0xe0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0,
                0xe0, 0xe1, 0xe3, 0xc3, 0xc3, 0xc7, 0x40, 0x00, 0x00, 0x00, 0xc7, 0xc3, 0xc3, 0xe3, 0xe1, 0xe1, 0xf0, 0xf8, 0xf8, 0xfc, 0xf8, 0xe0, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xa0, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00,
                0x70, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x70, 0x70, 0x70, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x70, 0x70, 0x70, 0xf0, 0xf0,
                0xf0, 0xf0, 0xf0, 0x70, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x03,
                0x00, 0x00, 0x80, 0x80, 0x80, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0xe0, 0xc0, 0x70, 0xf8, 0xfc, 0xfc, 0xff, 0x7b, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xfe, 0xf8, 0xf0, 0xe1, 0xc3, 0x81, 0x01, 0x30, 0x38, 0x78, 0x7c, 0xfc, 0xfc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfc,
                0xfc, 0xfc, 0x78, 0x38, 0x30, 0x00, 0x01, 0x03, 0x81, 0xc0, 0xe0, 0xf8, 0xfe, 0x7f, 0x3f, 0x0f, 0x87, 0xc3, 0xe1, 0xc3, 0x87, 0x0f, 0x1f, 0x7f,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfe, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xf8, 0xf8,
                0x78, 0x78, 0x38, 0x38, 0x18, 0x18, 0x00, 0x28, 0x30, 0x30, 0x30, 0x18, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0xe0, 0xf8, 0xfc, 0xfe, 0xff, 0xff,
                0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xe0, 0x81, 0x01, 0x01, 0x01, 0x01, 0x01, 0x19, 0x39, 0x31, 0x31, 0x38, 0x20, 0x10, 0x1f, 0x3f, 0x3f, 0x7f,
                0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

    };

    Dev_OLed_4P_Show(&stDev_OLed_4p,
                     0, 0,
                     (uint8_t*)pic,
                     102, 64);
}

void App_Button3_Demo(void* pArgs)
{
    (void)pArgs;
    const uint8_t zh16x16[][24] = {
/* 0 H */ {0xfc,0x20,0x20,0x20,0x20,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,},
/* 1 U */ {0xfc,0x00,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,},
/* 2 A */ {0x00,0xc0,0xb0,0x8c,0xb0,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,},
/* 3 W */ {0x1c,0xe0,0x00,0xe0,0x1c,0xe0,0x00,0xe0,0x1c,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,},
/* 4 E */ {0xfc,0x24,0x24,0x24,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
/* 5 I */ {0x04,0xfc,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}
    };
    uint8_t x = 24;
    Dev_OLed_4P_Clear(&stDev_OLed_4p);

    for(int i=0;i<6;i++)
    {
        uint8_t* u8Font = (uint8_t*)zh16x16[i];

        Dev_OLed_4P_Show(&stDev_OLed_4p,
                         x, 4,
                         u8Font,
                         12, 12);
        x+=12;
    }

}

void App_Uart_Rx_Demo(void* pArgs)
{
    (void)pArgs;
    uint8_t u8RxData[100];
    uint16_t u16RxLen = 0;
    Dev_Uart_Receive(&stDev_Uart1, u8RxData, &u16RxLen);
    Dev_Uart_Transmit(&stDev_Uart1, u8RxData, u16RxLen);
}

void App_Uart_Tx_Demo(void* pArgs)
{
    (void)pArgs;
    Dev_Uart_SetBaudrate(&stDev_Uart1, 115200);
}

